apiready = function(){

}
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../swiper","../../dialog"],function(V,$api,$,app,service,Swiper,dialog){
	var vm = {
		el: '.container',
		data: {
			list: [],
			banner: '',
			have_data: true,
			is_banner: true,
			page: 1,
			userInfo: '',
			bs: ""	//ajax弹出服务器提示控制变量
		},
		methods: {
			init: function(){
				if ($api.getStorage("user")) {
						this.userInfo = $api.getStorage("user").data;
						this.bs = 1;
				}
				if(this.have_data){
					//--商品列表
					this.getList();
				}else{
					app.toast("没有更多数据了！");
				}
				if(this.is_banner){
					//--轮播图
					this.getBanner();
				}
			},
			toGame: function(){
				if (this.bs == "") { //游客模式，没有缓存
						dialog.alert({
								title: '游客模式',
								msg: '体验更多功能，请先登录',
								buttons: ['取消', '确定']
						}, function(ret) {
								if (ret.buttonIndex == 2) { //确认
										api.closeToWin({
												name: 'WeChat_login'
										});
								}
						})
				}else{
					api.openWin({
							name: 'my_shop',
							url: 'widget://html/game/ball0.html',
							reload: true
					});
				}
			},
			//--获取列表数据
			getList: function(){
				var self = this;
				app.ajax(service.getYzcList,{
					data: {
						values: {
							unionid: $api.getStorage("shop_unionid"),
							is_yzc: 1,
							page: self.page
						}
					}
				},function (res) {
					console.log("yzc_："+JSON.stringify(res));
					if(res.code == 0){
						if(Array.isArray(res.data)){
							for(var i=0; i < res.data.length; i++){
								self.list.push(res.data[i]);
							}
						}else{
							for(var i=0; i < res.data.list.length; i++){
								self.list.push(res.data.list[i]);
							}
						}
						self.page++;
						self.have_data = res.data.length <= 0 ? false : true;
					}
				});
			},
			//--获取轮播图
			getBanner: function(){
				var self = this;
				app.ajax(service.getYzcBanner,{
					data: {
						values: {
							unionid: $api.getStorage("shop_unionid"),
							bs: this.bs
						}
					}
				},function (res) {
					//console.log("yzc_banner："+JSON.stringify(res));
					if(res.code == 0){
						self.banner = res.data;
						self.is_banner = false;
						$api.setTimeout(function(){
							self.initSwiper();
						},1000);
					}
				});
			},
			//--去商品详情
			goGoodsDetail: function(et){
				var goodsid = +et.currentTarget.dataset.goodsid;
				if (!goodsid) {
					return;
				}
				app.openWin("buyGoodsYzc",{
					goodsId: goodsid
				});
			},
			initSwiper: function(){
				var mySwiper = new Swiper('.swiper-container', {
		          	pagination: {
		            	el: '.swiper-pagination'
		          	}
		        });
			}
		},
		mounted: function() {
			var self = this;
	        //--下拉刷新
	        app.refreshHeaderInfo(function(){
	        	self.list = [];
	        	self.page = 1;
	        	self.have_data = true;
	        	self.init();
	        });
			var self = this;
			//--加载更多
			api.addEventListener({
				name: 'scrolltobottom',
				extra:{
					threshold: 1500            //设置距离底部多少距离时触发，默认值为0，数字类型
				}
			}, function(ret, err){
				self.init();
			});
		},
		created: function(){
			this.init();
		}
	};
	//var shopVue = new Vue(vm);
	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
